// MsgListview.cpp : implementation file
//

#include "stdafx.h"
#include "MyFtp.h"
#include "MsgListview.h"


// CMsgListview

IMPLEMENT_DYNCREATE(CMsgListview, CListView)

CMsgListview::CMsgListview()
{

}

CMsgListview::~CMsgListview()
{
}

BEGIN_MESSAGE_MAP(CMsgListview, CListView)
END_MESSAGE_MAP()


// CMsgListview diagnostics

#ifdef _DEBUG
void CMsgListview::AssertValid() const
{
	CListView::AssertValid();
}

#ifndef _WIN32_WCE
void CMsgListview::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
#endif
#endif //_DEBUG


// CMsgListview message handlers

void CMsgListview::OnInitialUpdate()
{
	CListView::OnInitialUpdate();

	SetWindowLong(m_hWnd,GWL_STYLE,WS_VISIBLE|LVS_EDITLABELS|WS_CHILD|WS_BORDER|LVS_REPORT);
	CListCtrl* pList=&GetListCtrl();
	DWORD oldStyle = pList->GetExtendedStyle();
	pList->SetExtendedStyle(oldStyle|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	//col 1
	pList->SetTextColor(RGB(0,0,255));
	CString m_Clo[]={_T("Date"),_T("Message")};
	pList->InsertColumn(0,m_Clo[0]);
	pList->SetColumnWidth(0,120);
	//col 2
	pList->InsertColumn(1,m_Clo[1]);
	pList->SetColumnWidth(1,1000);
}

void CMsgListview::TextOut(const char* pszText)
{
	int length = (int)strlen(pszText) + 1;
	TCHAR* pText = new TCHAR[length];
	MultiByteToWideChar(CP_ACP, 0, pszText, -1, pText, length);
	CListCtrl& theList = GetListCtrl();
	CTime t = CTime::GetCurrentTime();
	CString szDatetime = t.Format(_T("%c"));
	int index = theList.InsertItem(theList.GetItemCount(), szDatetime);
	theList.SetItemText(index, 1, pText);
	delete[] pText;
}
